﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Data;
using System.Collections.Specialized;


public partial class Admin_User_management : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    
    public void clear()
    {
        txtEmail.Text = "";
        txtFullname.Text = "";
        txtPassword.Text = "";
        txtUsername.Text = "";
        //ddlRoleid.Text="";
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
        byte[] hashedBytes;
        UTF8Encoding encoder = new UTF8Encoding();
        hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(txtPassword.Text));
        ClassUser a = new ClassUser();
        a.UpdateUser(txtUsername.Text, encoder.GetString(hashedBytes), txtFullname.Text, txtEmail.Text, ddlRoleid.SelectedIndex);
        GridView1.DataBind();
        clear();

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtUsername.Text=HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[2].Text);;
        txtPassword.Text=HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text);;
        txtFullname.Text=HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[4].Text);;
        txtEmail.Text=HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[5].Text);;
        ddlRoleid.Text = HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[6].Text); ;
    }

    protected void Button3_Click(object sender, EventArgs e)
    {

        ClassUser a = new ClassUser();
        a.DeleterUser(txtUsername.Text);
        GridView1.DataBind();
        clear();
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/Add_user.aspx");
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        Button2.Visible = true;
        Label1.Visible = true;
        Label2.Visible = true;
        Label3.Visible = true;
        Label4.Visible = true;
        Label5.Visible = true;
        Label6.Visible = true;
        txtEmail.Visible = true;
        txtFullname.Visible = true;
        txtPassword.Visible = true;
        txtUsername.Visible = true;
        ddlRoleid.Visible = true;
        
    }
}
